<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方案维护页面</title>
    <script src="../../res/layui/layui.js" charset="utf-8" media="all"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/js/xm-select.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/js/login_common.js" type="text/javascript" charset="utf-8"></script>
    <script>
        //全局同步
        $.ajaxSetup({
            async : false
        });
    </script>
    <style>
        #btn{
            margin-top: 8px;
            margin-left: 152px;
        }
        .message{
            width: 619px;
            line-height: 44px;
            color: #ffd5bc;
            overflow: hidden;
        }
        .message .input{
            width: 219px;
            height: 38px;
            line-height: 28px;
            border: none;
            background: #ffffff;
            padding-left: 20px;
            color: #929aa1;
            font-family: Microsoft YaHei;
            border-bottom: #dbdbdb solid 1.1px;
        }
        .message .liulan{
            width: 78px;
            height: 38px;
            border: 1px solid #5fb878;
            background: #5fb878;
            color: #ffffff;
            cursor: pointer;
        }
        .message .files{
            position:absolute;
            left:-1000px;
            top:52px;
            heigth:26px;
            cursor:pointer;
            filter: Alpha(opacity=0);
            -moz-opacity:0;opacity:0;
        }
        #div{
            height:20px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" id="from">
    <input id="schemeId" name="schemeId" hidden></input>
    <input id="coachName" name="coachName" hidden></input>
    <input id="coachId" name="coachId" hidden></input>
    <div class="layui-form-item">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input type="text" id="schemeName" name="schemeName" lay-verify="schemeName" autocomplete="off" placeholder="请输入方案名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">方案类型</label>
        <div class="layui-input-inline">
            <input  type="text" class="layui-input layui-disabled" disabled id="schemeType" name="schemeType" lay-verify="schemeType" autocomplete="off" placeholder="" class="layui-input" value="运动康复方案" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">运动员</label>
        <div class="layui-input-block">
            <div id="demo1" name="athleteName" style="width: 300px; margin: 20px;" lay-verify="demo1">

            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">说明:建议</label>
        <div class="layui-input-block">
            <textarea id="exp" name="exp" required lay-verify="exp" placeholder="请填写说明或建议" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件一</label>
        <div class="layui-input-block">
           <!-- <div class="message">
                <form method="post" action="" enctype="multipart/form-data">
                    <input type="text" name="txt" class="input" value="非必填" disabled="disabled">
                    <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;" value="上传图片" size="30" onclick="f.click()" class="liulan">
                    <input type="file" id="f" onchange="txt.value=this.value" name="file11" style="height:26px;" class="files" size="1" hidefocus="">
                </form>
            </DIV>-->
            <input type="file" name="file11">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件二</label>
        <div class="layui-input-block">
            <!--<div class="message">
                <form method="post" action="" enctype="multipart/form-data">
                    <input type="text" name="txt" class="input" value="非必填" disabled="disabled">
                    <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;" value="上传图片" size="30" onclick="f.click()" class="liulan">
                    <input type="file" id="f" onchange="txt.value=this.value" name="file22" style="height:26px;" class="files" size="1" hidefocus="">
                </form>
            </div>-->
            <input type="file" name="file22">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件三</label>
        <div class="layui-input-block">
            <!--<div class="message">
                <form method="post" action="" enctype="multipart/form-data">
                    <input type="text" name="txt" class="input" value="非必填" disabled="disabled">
                    <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;" value="上传图片" size="30" onclick="f.click()" class="liulan">
                    <input type="file" id="f" onchange="txt.value=this.value" name="file33" style="height:26px;" class="files" size="1" hidefocus="">
                </form>
            </div>-->
            <input type="file" name="file33">
        </div>
    </div>

    <div style="width: 216px; margin: 0;">
        <button type="button" id="btn" class="layui-btn layui-btn-fluid" lay-submit lay-filter="formDemo">提交</button>
    </div>
    <div id="div"></div>
</form>
<!--表单监听-->
<script>
    $(function(){
        EmpAthlete();
    })
    var form = null;
        //Demo
        layui.use(['form','laydate'], function(){

            form = layui.form;

            /*不为空判定*/
            form.verify({
                schemeName: function(value){
                    if(value==""){
                        return '必须要写方案名称哦';
                    };
                }
                ,resultTime:function(value){
                    if(value==""){
                        return '必须要写反馈时间哦';
                    };
                }
                ,resultExp:function(value){
                    if(value==""){
                        return '必须要写反馈情况哦';
                    };
                }
                ,resultFile:function(value){
                    if(value==""){
                        return '必须要写附件哦';
                    };
                }
                ,exp:function(value){
                    if(value==""){
                        return '必须要提供建议哦';
                    };
                }
            });

            finByCoach(form);
            //监听提交
            form.on('submit(formDemo)', function(data){

                var formData = new FormData(document.getElementById("from"));
                var url="../../AtsSchemeAction/addorupdate?type="+$('#schemeType').val()
                $.ajax({
                    url:url,
                    type:"post",
                    data:formData,
                    async:false,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        if(obj.num==1){
                            layer.msg("操作成功",{
                                icon:1,
                                time:1000 //1秒关闭(如果不配置默认三秒)
                            },function(){
                                //关闭当前层
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                //刷新父页面
                                parent.location.reload();
                            });
                        }else{
                            alert("操作失败")
                        }
                    },
                    error:function(e){
                    }
                });
                return false;
            })

            var id=getQueryStringOne("id");

            if(id!=null){
                findById();//修改页面的赋值
                findByIdtwo();/*说明建议赋值*/
            }

        });

        //拿到上一个页面传过来的id
        function getQueryStringOne(key) {
            var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return decodeURI(r[2]);
            return null;
        }
        //修改页面的赋值
        function findById(){
            var id=getQueryStringOne("id");
            $("#schemeId").val(id);
            var url="../../AtsSchemeAction/finbyid";
            var data={id:id};
            $.post(url,data,function(obj){
                $("#schemeName").val(obj.schemeName);
                $("#schemeType").val(obj.schemeType);
                $("#resultTime").val(obj.resultTime);
                $("#resultExp").val(obj.resultExp);
                $("#resultEffect").val(obj.resultEffect);
                $("#resultFile").val(obj.resultFile);
                console.info(obj.coachId+"----"+obj.coachName);
                $("#coachName_"+obj.coachId).prop("checked",true);
                $("#resultEffect_"+obj.resultEffect).prop("checked",true);
                form.render();
            },"json");
        }
        /*说明建议赋值*/
        function findByIdtwo(){
            var id=getQueryStringOne("id");
                var url="../../UserseController/selectbyschemeidKF";
                var data={id:id};
                var arr=[];
                $.post(url,data,function(obj){
                    $.each(obj.data,function(index,item){
                        arr.push(item.athleteId);
                    })
                    $("#exp").val((obj.data[0]).exp);
                },"json");
                return arr;
        }
       /* 教练员赋值*/
        function finByCoach() {
            $("#coachName").val(loginObj.manager.usName);
            $("#coachId").val(loginObj.manager.usWaiid);
            form.render();
        }
        /*运动员下拉框赋值*/
        function EmpAthlete(){
            var i=0;
            var id=getQueryStringOne("id");
            var url="../../AtsEmpAthleteAction/findbycoachId?Id="+loginObj.manager.usWaiid;
            var arr=[];
            var idsarr = findByIdtwo();
            $.post(url,function(obj){
                $.each(obj,function(index,item){
                    if(id==null){
                        arr.push({name:item.athleteName,value:item.athleteId});
                    }else if(id!=null){
                        arr.push({name:item.athleteName,value:item.athleteId});
                        $.each(idsarr,function(ins,it){
                            if(item.athleteId==idsarr[ins]) {
                                arr.splice(ins,1);
                                arr.push({name: item.athleteName, value: item.athleteId, selected: true})
                            }
                        })
                    }
                })
            },"json");
            console.info(arr);
           /* layui下拉框样式*/
            var demo1 = xmSelect.render({
                el: '#demo1',
                filterable: true,
                name: 'ids',
                data: arr
            })
        }
</script>
</body>
</html>